package com.indusfo.spc.controller;

import com.indusfo.spc.pojo.BatchRepair;
import com.indusfo.spc.service.BatchRepairService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author liub
 * @Date 2019/12/6 8:52
 * @Version 1.0
 */

@Controller
@RequestMapping("/service/batchRepair")
public class BatchRepairController {

    @Autowired
    private BatchRepairService batchRepairService;

    /**
     * 查询
     */
    @RequestMapping(value = "/queryBatchRepair")
    @ResponseBody
    public JSONObject queryBatchRepair(BatchRepair batchRepair) {
        JSONObject json = batchRepairService.queryBatchRepair(batchRepair);
        return json;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/insertBatchRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject insertBatchRepair(BatchRepair batchRepair) {
        JSONObject json = batchRepairService.insertBatchRepair(batchRepair);
        return json;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/updateBatchRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject updateBatchRepair(BatchRepair batchRepair) {
        JSONObject json = batchRepairService.updateBatchRepair(batchRepair);
        return json;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/deleteBatchRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteBatchRepair(@RequestParam("batchRepairIds") List<Integer> batchRepairIds, Integer dataState) {
        dataState = 2;
        JSONObject json = batchRepairService.deleteBatchRepair(batchRepairIds, dataState);
        return json;
    }

    /**
     * 启停
     */
    @RequestMapping(value = "/definedBatchRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject definedBatchRepair(@RequestParam("batchRepairIds") List<Integer> batchRepairIds, Integer dataState) {
        JSONObject json = batchRepairService.deleteBatchRepair(batchRepairIds, dataState);
        return json;
    }

    /**
     * 级联删除工序流程关联的工位、采集参数、关键物料、不良现象
     */
    @RequestMapping(value = "/deleteCascadeBatchRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteCascadeBatchRepair(@RequestParam("batchRepairIds") List<Integer> batchRepairIds, Integer dataState) {
        dataState = 2;
        try {
            return batchRepairService.deleteCascadeBatchRepair(batchRepairIds, dataState);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONObject.build(JSONObject.ERROR, e.getMessage(), null);
        }
    }


    /**
     * 批次流程维修工序
     */
    @RequestMapping(value = "/saveBatchRepairFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveBatchRepairFlow(@RequestBody BatchRepair batchRepair) {
        JSONObject json = batchRepairService.saveBatchRepairFlow(batchRepair);
        return json;
    }

    /**
     * 批次流程维修采集参数
     */
    @RequestMapping(value = "/saveBatchRepairDete", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveBatchRepairDete(@RequestBody BatchRepair batchRepair) {
        JSONObject json = batchRepairService.saveBatchRepairDete(batchRepair);
        return json;
    }
}
